package main

import (
	"com.opennews.openplatform/web_api/bootstrap"
	"com.opennews.openplatform/web_api/controllers"
	"github.com/gin-gonic/gin"
)

func init() {
	// Starts the initialization.
	bootstrap.Init()
}

// Uses gin in main & controller functions only. Because controller is tightly coupled with web framework, here is Gin.
// If we have to switch the framework the main function and controller should be the only place we have to refactor.
// For example, if we use gin.H everywhere that means we have more work to do during such refactoring.
func main() {
	// Default returns an Engine instance with the Logger and Recovery middleware already attached.
	router := gin.Default()

	// Uses middleware to check on access permission.
	router.Use(controllers.CheckAccessPermission)

	// Generates all controller routes.
	controllers.GenerateRoutes(router)

	// listens and serves on 0.0.0.0:8080 (for windows "localhost:8080")
	router.Run()
}
